package com.insta.android.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class BddOpenHelper extends SQLiteOpenHelper {
	
	private static final String TABLE_PLAYLIST = "tb_playlist";
	private static final String PLA_ID = "pla_id";
	private static final String PLA_NOM = "pla_nom";
	
	private static final String CREATE_TB_PLAYLIST = "CREATE TABLE " + TABLE_PLAYLIST + " ("
							+ PLA_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
							+ PLA_NOM + " TEXT NOT NULL); ";
	
	
	private static final String TABLE_MUSIC = "tb_music";
	private static final String MUS_ID = "mus_id";
	private static final String MUS_FILENAME = "mus_filename";
	private static final String MUS_TITLE = "mus_title";
	private static final String MUS_ARTIST = "mus_artist";
	private static final String MUS_ALBUM = "mus_album";
	private static final String MUS_DUREE = "mus_duree";
	private static final String MUS_RATING = "mus_rating";
	
	private static final String CREATE_TB_MUSIC = "CREATE TABLE " + TABLE_MUSIC + " ("
							+ MUS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
							+ MUS_FILENAME + " TEXT NOT NULL, "
							+ MUS_TITLE +" TEXT, "
							+ MUS_ARTIST +" TEXT, "
							+ MUS_ALBUM +" TEXT, "
							+ MUS_DUREE +" INTEGER, "
							+ MUS_RATING +" INTEGER );";

	
	private static final String TABLE_PLAYLIST_ASSOC_MUSIC = "tb_pla_assoc_mus";
	private static final String PAM_ID = "pam_id";
	private static final String PAM_PLA_ID = "pam_pla_id";
	private static final String PAM_MUS_ID = "pam_mus_id";
	
	private static final String CREATE_TB_PLAYLIST_ASSOC_MUSIC = "CREATE TABLE " + TABLE_PLAYLIST_ASSOC_MUSIC + " ("
							+ PAM_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
							+ PAM_PLA_ID + " INTEGER, "
							+ PAM_MUS_ID + " INTEGER );";
	
	
	public BddOpenHelper(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
	}


	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(CREATE_TB_MUSIC);
		db.execSQL(CREATE_TB_PLAYLIST);
		db.execSQL(CREATE_TB_PLAYLIST_ASSOC_MUSIC);
	}

	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE " + TABLE_PLAYLIST_ASSOC_MUSIC + ";");
		db.execSQL("DROP TABLE " + TABLE_MUSIC + ";");
		db.execSQL("DROP TABLE " + TABLE_PLAYLIST + ";");
		onCreate(db);
	}
}
